<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px">
      <el-form-item label="生产订单号" prop="scddErpId" label-width="90px">
        <el-input v-model="queryParams.scddErpId" :disabled="true" />
      </el-form-item>
      <el-form-item label="子件名称" prop="childName">
        <el-input v-model="queryParams.childName" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border>
      <el-table-column label="生产订单号" align="center" prop="scddErpId" />
      <el-table-column label="子件编码" align="center" prop="childCode" />
      <el-table-column label="子件名称" align="center" prop="childName" />
      <el-table-column label="基本用量" align="center" prop="basicDosage" />
      <el-table-column label="单位" align="center" prop="unit" />
    </el-table>
    <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>
<script>
  import { listBOMData } from '@/api/function/bomData';
  export default {
    name: "bomData",
    props: {
      scddErpId: {
        type: String,
        default: "",
      },
      planCode: {
        type: String,
        default: "",
      }
    },
    watch: {
      scddErpId: {
        handler(newVal, oldVal) {
          if (newVal) {

            this.queryParams.scddErpId = newVal;
            this.defaultScddErpId = newVal;
            this.getList();
          }
        },
        immediate: true,
        deep: true,
      },
      planCode: {
        handler(newVal, oldVal) {
          if (newVal) {
            this.queryParams.planCode = newVal;
            this.defaultPlanCode = newVal;
            this.getList();
          }
        },
        immediate: true,
        deep: true,
      },

    },
    created() { },
    data() {
      return {
        // 总条数
        total: 0,
        // 字典表格数据
        dataList: [],
        // 默认id
        defaultScddErpId: 0, defaultPlanCode: '',
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
      };
    },
    created() { },
    mounted() { },
    methods: {
      /** 查询BOM清单列表 */
      getList() {
        this.loading = true;
        this.queryParams.planCode = this.planCode;
        listBOMData(this.queryParams).then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;


        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.scddErpId = this.defaultScddErpId;
        this.queryParams.planCode = this.defaultPlanCode
        this.handleQuery();
      },
    },
  };
</script>